package com.example.day11.homework;

public class SynchroThread {

    private  int  num=0;

    public  synchronized   void printUpder(){
        for(char i='A';i<='Z';i++){

            while (num!=0){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.print(i);
            num=1;
            notifyAll();
        }
    }

    public  synchronized   void printNum(){
        for(int i=1;i<=26;i++){

            while (num!=1){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.print(i);
            num=2;
            notifyAll();
        }
    }

    public  synchronized   void printlower(){
        for(char i='a';i<='z';i++){

            while (num!=2){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.print(i);
            num=0;
            notifyAll();
        }
    }
}

class  TestSynChro{
    public static void main(String[] args) {
        SynchroThread synchroThread=new SynchroThread();
        new Thread(()-> synchroThread.printUpder()).start();
        new Thread(()-> synchroThread.printNum()).start();
        new Thread(()-> synchroThread.printlower()).start();


    }
}
